<script setup>
import comps from "@/components/utils/component_selector.js"
import { computed, defineProps } from 'vue'
const props = defineProps(["meta", "vm"]);
const { meta } = props;
const { model } = meta;
const parentVm = props.vm;
const dataModel = parentVm.getModel(model);

const childs = computed(() => {
  return meta.controls || [];
});

function handleConfirm() {
  let promise = dataModel.args.promise;
  dataModel.visible = false;
  dataModel.args.data.param = dataModel.data;
  dataModel.value = dataModel;
  if (promise) {
    promise.resolve();
  }
}

function handelCancle() {
  dataModel.visible = false;
  if (dataModel.args.promise) {
    dataModel.args.promise.reject();
  }
}
</script>
<template>
  <el-dialog v-model="dataModel.visible" :title="meta.title" width="500" :key="meta.id">
    <component v-for="item in childs" :is="comps(item)" :meta="item" :vm="vm" />
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="handelCancle">取 消</el-button>
        <el-button type="primary" @click="handleConfirm">
          确 定
        </el-button>
      </div>
    </template>
  </el-dialog>
</template>